package Utils;


import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Random;

import GerenciadorDeSom.SoundPlayer;
import Main.GamePanel;
import Map.TileMap;
import enemies.Enemy;

public class Constantes {
	@SuppressWarnings("unused")
	private static final int PWIDTH = 900;
	@SuppressWarnings("unused")
	private static final int PHEIGHT = 500;
	public static SoundPlayer soundplayer;
	public static ArrayList<BufferedImage> imagensDosInimigos;
	public static ArrayList<TileMap> listaMapas;
	public static ArrayList<TileMap> listaMapasParaReiniciar;	
	public static ArrayList<Enemy> ListaInimigos;
	public static ArrayList<TipoCoord> listaCoords;
	public static int mapaAtual = 0;
	public static ArrayList<BufferedImage>listaDeImagemCenario;
	public static ArrayList<Ponto2D>listaDePosicoesIniciais;
	public static Random rnd = new Random();
	public static ArrayList<BufferedImage> listaDeBuildsTorres = new ArrayList<BufferedImage>();
	public static BufferedImage sangue;
	public static BufferedImage chamuscado;
	// SOUNDTRACK - Alterar para sons finais
	public final static int SFX_SOM = 0;
	public final static int SFX_HIT = 1;
	public final static int SFX_PUNCH = 2;
	public final static int SFX_THROW = 3;
	public final static int BGM_INTRO = 4;
	public final static int SFX_LIBERA_WAVE = 5;
	public final static int BGM_TELA_BUILD = 6;
	public final static int BGM_TELA_CREDITOS = 7;
	public final static int BGM_TELA_GAME_OVER = 8;
	public final static int BGM_TELA_WIN = 9;
	public final static int BGM_WAVE_ESPERA = 10;	
	public final static int SFX_CLICK = 11;
	public final static int SFX_FIX = 12;
	public final static int SFX_SELL = 13;
	public final static int SFX_BASEHIT = 14;
	public final static int SFX_DEATH = 15;
	public final static int SFX_CANHAO = 16;

	public static void carregaMapas(String arq){
		listaMapas = new ArrayList<TileMap>();
		listaMapasParaReiniciar =new ArrayList<TileMap>();
		listaDeImagemCenario = new ArrayList<BufferedImage>();
		listaDePosicoesIniciais = new ArrayList<Ponto2D>();
		Ponto2D ponto;
		//File file = new File(arq);
		InputStream is = GamePanel.instance.getClass().getResourceAsStream("/"+arq);
		
		
    	String str = "";
        try {      
//        	FileInputStream fstream = new FileInputStream(file);
//            DataInputStream in = new DataInputStream(fstream);
            BufferedReader dados = new BufferedReader(new InputStreamReader(is));
            listaMapas.clear();
           
            while((str = dados.readLine())!=null){

            	if (str.charAt(0) != '#') {            		
            		String str2[] = str.split(";");
            		;
            		BufferedImage img = Utilidades.LoadImage(str2[2]);
            		TileMap map = new TileMap(img, Integer.parseInt(str2[3]), Integer.parseInt(str2[4]), str2[1]);
            		map.AbreMapa(str2[5]);
            		map.numPaths = Integer.parseInt(str2[6]);
            		map.parseCoord(str2[7]);
//            		System.out.println("wave"+str2[8]);
            		map.parseWave(str2[8]);
            		listaDeImagemCenario.add(Utilidades.LoadImage(str2[9]));
            		ponto = new Ponto2D();
            		ponto.x = Integer.parseInt(str2[10]);
            		ponto.y = Integer.parseInt(str2[11]);
            		listaDePosicoesIniciais.add(ponto);
            		ponto=null;
            		
					listaMapas.add(map);
					listaMapasParaReiniciar.add(map);
				}
            }
        } catch (IOException e) {
            e.printStackTrace();
        }  
        loadBuildsTorres();
        
	}
	
	
	
	public static void loadBuildsTorres(){
		
	
		for(int i=0; i<12; i++){
			
			listaDeBuildsTorres.add(Utilidades.LoadImage("/bildsTorres/torre_"+i+".png"));
		}
		
	}
	
	public static void carregaSons(String arq) {
		soundplayer = new SoundPlayer();
		String str = "";
		InputStream is = GamePanel.instance.getClass().getResourceAsStream("/"+arq);
		BufferedReader dados = null;

		try {
//	    	FileInputStream fstream = new FileInputStream(file);
//	        DataInputStream in = new DataInputStream(fstream);
	        dados = new BufferedReader(new InputStreamReader(is));
			while ((str = dados.readLine()) != null) {
				if (str.charAt(0) != '#') {
					String str2[] = str.split(";");
					String arquivo = new String();
					String loop = new String();
					arquivo=str2[1];
					loop = str2[2];
					String v = arquivo; 
					String v1 = loop;
					soundplayer.addtrack(v, 1, Boolean.parseBoolean(v1));
				}
			}
		} catch (IOException e) {
			System.out.println("caauhsasihuasidhaisudhfuashdfuiashdfiuashdfasdf");
			e.printStackTrace();
		}
	}

	public static void carregaImagemInimigos(String arq) {
		String str = "";
		//File file = new File(arq);
		InputStream is = GamePanel.instance.getClass().getResourceAsStream("/"+arq);
		BufferedReader dados = null;
		imagensDosInimigos = new ArrayList<BufferedImage>();		
		try {
//	    	FileInputStream fstream = new FileInputStream(file);
//	        DataInputStream in = new DataInputStream(fstream);
	        dados = new BufferedReader(new InputStreamReader(is));
			while ((str = dados.readLine()) != null) {
				if (str.charAt(0) != '#') {
					String str2[] = str.split(";");					
					imagensDosInimigos.add(Utilidades.LoadImage(str2[1]));
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void carregaImagemManchas(){
		sangue = Utilidades.LoadImage("/inimigos/blood.png");
		chamuscado = Utilidades.LoadImage("/inimigos/explosion.png");
	}
}